// 公用样式
require('../../assets/css/index.less');
// 当前页面样式
require('./publishDynamic.less');
// 字体图标
require( '../../assets/fonts/iconfont.css' )
// 公用js
let dom=require('../../utils/dom.js');
let https=require( '../../utils/https.js' )
let local=require( '../../utils/local.js' )

dom.ready(function(){

    dom.isLogin()
    // 省份
    let provinceId;
    dom.get('#showProvince').addEventListener('click', function () {
        https.get('/api/shared/province',{},function(res){
            if(res.errno==0){
                let ProvinceData=res.data.map(v=>{
                    return {
                        label: v.name,
                        value: v.id
                    }
                })

                weui.picker(ProvinceData, {     
                    onConfirm: function (result) {
                        dom.get('#province').innerHTML=result[0].label;
                        
                        provinceId=result[0].value
                        console.log(provinceId);
                    },
                    title: '省份'
                });     
            } 
        })
    });
    // 城市
    let cityId
    dom.get('#showCity').addEventListener('click', function () {
        console.log(provinceId);
        if(provinceId){
            https.get('/api/shared/city',{provinceId},function(res){
                console.log(typeof provinceId);
                console.log(res,"1111");
                if(res.errno==0){
                    let ProvinceData=res.data.map(v=>{
                        return {
                            label: v.name,
                            value: v.id
                        }
                    })
                    weui.picker(ProvinceData, {
                        onConfirm: function (result) {
                            dom.get('#city').innerHTML=result[0].label
                            cityId=result[0].value
                        },
                        title: '城市'
                    });
                    
                }
            })
        }
    });
    // 上传头像
 

    fileBtn.addEventListener('change', function () { 
        let f = this.files[0];
        let fd = new FormData();
        fd.append('file', f);
        https.upLoadPic('/api/shared/uploadPortrait1', fd, function (res) { 
            console.log(res);
            if (res.errno == 0) { 
                first.style.background=`url('http://47.96.154.185:3701${res.data.url}')`
                // first.src=`http://47.96.154.185:3701${res.data.url}`
            }
        })
  
    })




    dom.get('#changeBtn').addEventListener('click',function(){
        window.history.go(-1)
    })




    // 窗口加载事件
})